import React from 'react'
import PropTypes from 'prop-types'
import {Input,Select,Form} from 'antd'

export default class AddForm extends React.Component {
    AddForm = React.createRef()

    static propTypes = {
        setAddForm: PropTypes.func.isRequired, // 用来传递form对象的函数 
    }

    state={addValue:{}}

    UNSAFE_componentWillMount(){
        this.props.setAddForm(this.AddForm)
    }
    
    onValuesChange=(changedValues, allValues)=>{
         this.setState(state =>({  addValue: allValues }))
    }
     render(){
        const {categories,parentId} = this.props
        return (
       <Form ref={this.AddForm} onValuesChange={this.onValuesChange} initialValues={{  parentId: parentId,categoryName:'水果'}}  >
            <Form.Item label="分类选项"  required tooltip="不能为空" name="parentId">
                    <Select> 
                        <Select.Option value='0'>一级分类</Select.Option>
                        {
                            categories.map((c,index)=><Select.Option value={c._id} key={index+1}>{c.name}</Select.Option>)
                        }
                        </Select>
            </Form.Item>
            <Form.Item label="分类名称" required name="categoryName">
                    <Input placeholder='请输入分类名称'/>
            </Form.Item>
       </Form>
      )
     }
   
    //    <Form>
    //         { form.getFieldDecorator('list.name', {
    //                     initialValue:'list.name',
    //                     rules:[]
    //                     })(
    //                         <Input autoComplete="off" placeholder='请输入角色'/>
    //                     )
    //                 }
    //    </Form>
    
}
